import 'package:base_plugin/base_plugin.dart';
import 'package:dio/dio.dart';

/// 采购订单
class HttpQuotationService {
  /// 采购订单列表
  static Future<Response> quotationsList(int page, {String status, int issue_to, String keyword}) {
    return BaseConfig.httpBase.get('/api/quotations', {
      'page': page,
      'status': status,
      'issue_to': issue_to,
      'keyword': keyword,
    });
  }

  /// 创建采购订单
  static Future<Response> createQuotations({
    int contactId,
    String number,
    String issued_at,
    String due_at,
    String currency_code,
    double subtotal,
    double exclusive_tax_amount,
    double inclusive_tax_amount,
    double total,
    String notes,
    List item,
    List attachment_ids,
    String discount_type,
    double discount_amount,
  }) {
    return BaseConfig.httpBase.postJson('/api/quotations', {
      "contact_id": contactId,
      "number": number,
      "issued_at": issued_at,
      "due_at": due_at,
      "currency_code": currency_code,
      "subtotal": subtotal,
      "exclusive_tax_amount": exclusive_tax_amount,
      "inclusive_tax_amount": inclusive_tax_amount,
      "total": total,
      "notes": notes,
      "items": item,
      'discount_type': discount_type,
      'discount_amount': discount_amount,
      'attachment_ids': attachment_ids,
    });
  }

  /// 显示采购订单
  static Future<Response> showQuotations(int purchaseOrdersId) {
    return BaseConfig.httpBase.get('/api/quotations/$purchaseOrdersId', {});
  }

  /// 更新采购订单
  static Future<Response> updateQuotations(
    int id, {
    int contactId,
    String number,
    String issued_at,
    String due_at,
    String currency_code,
    double subtotal,
    double exclusive_tax_amount,
    double inclusive_tax_amount,
    double total,
    String notes,
    List item,
    List attachment_ids,
    String discount_type,
    double discount_amount,
  }) {
    return BaseConfig.httpBase.putJson('/api/quotations/$id', {
      "contact_id": contactId,
      "number": number,
      "issued_at": issued_at,
      "due_at": due_at,
      "currency_code": currency_code,
      "subtotal": subtotal,
      "exclusive_tax_amount": exclusive_tax_amount,
      "inclusive_tax_amount": inclusive_tax_amount,
      "total": total,
      "notes": notes,
      "items": item,
      'discount_type': discount_type,
      'discount_amount': discount_amount,
      'attachment_ids': attachment_ids,
    });
  }

  //删除
  static Future<Response> deleteQuotation(int id) {
    return BaseConfig.httpBase.deleteJson('/api/quotations/$id', {});
  }

  //拒绝
  static Future<Response> rejectedQuotation(int id) {
    return BaseConfig.httpBase.postJson('/api/quotations/$id/reject', {});
  }

  //拒绝
  static Future<Response> currencyRate(String date, String to_currency, {String from_currency = ""}) {
    return BaseConfig.httpBase.get('/api/common/currency_rate', {'from_currency': from_currency, 'date': date, "to_currency": to_currency});
  }

  //进行配送
  static Future<Response> deliver(int id) {
    return BaseConfig.httpBase.putJson('/api/quotations/$id/deliver', {});
  }

  //填写地址
  static Future<Response> deliveryQuotation(
    int id, {
    String address_country,
    String address_city,
    String address_postal_code,
    String address_line_1,
    String address_unit,
  }) {
    return BaseConfig.httpBase.postJson('/api/quotations/$id/delivery', {
      'address_country': address_country,
      'address_city': address_city,
      'address_postal_code': address_postal_code,
      'address_line_1': address_line_1,
      'address_unit': address_unit,
    });
  }
}
